home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Exercise6DE.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  13.1 KB  |  457 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPublishers 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Publishers"
  5.    ClientHeight    =   5580
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4650
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   5580
  13.    ScaleWidth      =   4650
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.TextBox txtInput 
  16.       DataField       =   "Comments"
  17.       DataMember      =   "comPublishers"
  18.       DataSource      =   "denBooks"
  19.       Height          =   285
  20.       Index           =   9
  21.       Left            =   1320
  22.       Locked          =   -1  'True
  23.       TabIndex        =   9
  24.       Text            =   "Text1"
  25.       Top             =   3360
  26.       Width           =   3255
  27.    End
  28.    Begin VB.TextBox txtInput 
  29.       DataField       =   "Fax"
  30.       DataMember      =   "comPublishers"
  31.       DataSource      =   "denBooks"
  32.       Height          =   285
  33.       Index           =   8
  34.       Left            =   1320
  35.       Locked          =   -1  'True
  36.       TabIndex        =   8
  37.       Text            =   "Text1"
  38.       Top             =   3000
  39.       Width           =   1575
  40.    End
  41.    Begin VB.TextBox txtInput 
  42.       DataField       =   "Telephone"
  43.       DataMember      =   "comPublishers"
  44.       DataSource      =   "denBooks"
  45.       Height          =   285
  46.       Index           =   7
  47.       Left            =   1320
  48.       Locked          =   -1  'True
  49.       TabIndex        =   7
  50.       Text            =   "Text1"
  51.       Top             =   2640
  52.       Width           =   1575
  53.    End
  54.    Begin VB.TextBox txtInput 
  55.       DataField       =   "Zip"
  56.       DataMember      =   "comPublishers"
  57.       DataSource      =   "denBooks"
  58.       Height          =   285
  59.       Index           =   6
  60.       Left            =   1320
  61.       Locked          =   -1  'True
  62.       TabIndex        =   6
  63.       Text            =   "Text1"
  64.       Top             =   2280
  65.       Width           =   1575
  66.    End
  67.    Begin VB.TextBox txtInput 
  68.       DataField       =   "State"
  69.       DataMember      =   "comPublishers"
  70.       DataSource      =   "denBooks"
  71.       Height          =   285
  72.       Index           =   5
  73.       Left            =   1320
  74.       Locked          =   -1  'True
  75.       TabIndex        =   5
  76.       Text            =   "Text1"
  77.       Top             =   1920
  78.       Width           =   1575
  79.    End
  80.    Begin VB.TextBox txtInput 
  81.       DataField       =   "City"
  82.       DataMember      =   "comPublishers"
  83.       DataSource      =   "denBooks"
  84.       Height          =   285
  85.       Index           =   4
  86.       Left            =   1320
  87.       Locked          =   -1  'True
  88.       TabIndex        =   4
  89.       Text            =   "Text1"
  90.       Top             =   1560
  91.       Width           =   3255
  92.    End
  93.    Begin VB.TextBox txtInput 
  94.       DataField       =   "Address"
  95.       DataMember      =   "comPublishers"
  96.       DataSource      =   "denBooks"
  97.       Height          =   285
  98.       Index           =   3
  99.       Left            =   1320
  100.       Locked          =   -1  'True
  101.       TabIndex        =   3
  102.       Text            =   "Text1"
  103.       Top             =   1200
  104.       Width           =   3255
  105.    End
  106.    Begin VB.TextBox txtInput 
  107.       DataField       =   "Company Name"
  108.       DataMember      =   "comPublishers"
  109.       DataSource      =   "denBooks"
  110.       Height          =   285
  111.       Index           =   2
  112.       Left            =   1320
  113.       Locked          =   -1  'True
  114.       TabIndex        =   2
  115.       Text            =   "Text1"
  116.       Top             =   840
  117.       Width           =   3255
  118.    End
  119.    Begin VB.TextBox txtInput 
  120.       DataField       =   "Name"
  121.       DataMember      =   "comPublishers"
  122.       DataSource      =   "denBooks"
  123.       Height          =   285
  124.       Index           =   1
  125.       Left            =   1320
  126.       Locked          =   -1  'True
  127.       TabIndex        =   1
  128.       Text            =   "Text1"
  129.       Top             =   480
  130.       Width           =   3255
  131.    End
  132.    Begin VB.CommandButton cmdHelp 
  133.       Caption         =   "&Help"
  134.       Height          =   375
  135.       Left            =   3240
  136.       TabIndex        =   19
  137.       TabStop         =   0   'False
  138.       Top             =   5160
  139.       Width           =   1215
  140.    End
  141.    Begin VB.CommandButton cmdDone 
  142.       Caption         =   "Do&ne"
  143.       Height          =   375
  144.       Left            =   3240
  145.       TabIndex        =   18
  146.       TabStop         =   0   'False
  147.       Top             =   4680
  148.       Width           =   1215
  149.    End
  150.    Begin VB.CommandButton cmdDelete 
  151.       Caption         =   "&Delete"
  152.       Height          =   375
  153.       Left            =   1680
  154.       TabIndex        =   17
  155.       TabStop         =   0   'False
  156.       Top             =   4680
  157.       Width           =   1215
  158.    End
  159.    Begin VB.CommandButton cmdEdit 
  160.       Caption         =   "&Edit"
  161.       Height          =   375
  162.       Left            =   120
  163.       TabIndex        =   16
  164.       TabStop         =   0   'False
  165.       Top             =   4200
  166.       Width           =   1215
  167.    End
  168.    Begin VB.CommandButton cmdCancel 
  169.       Caption         =   "&Cancel"
  170.       Height          =   375
  171.       Left            =   3240
  172.       TabIndex        =   15
  173.       TabStop         =   0   'False
  174.       Top             =   4200
  175.       Width           =   1215
  176.    End
  177.    Begin VB.CommandButton cmdSave 
  178.       Caption         =   "&Save"
  179.       Height          =   375
  180.       Left            =   1680
  181.       TabIndex        =   14
  182.       TabStop         =   0   'False
  183.       Top             =   4200
  184.       Width           =   1215
  185.    End
  186.    Begin VB.CommandButton cmdAddNew 
  187.       Caption         =   "&Add New"
  188.       Height          =   375
  189.       Left            =   120
  190.       TabIndex        =   13
  191.       TabStop         =   0   'False
  192.       Top             =   4680
  193.       Width           =   1215
  194.    End
  195.    Begin VB.CommandButton cmdNext 
  196.       Caption         =   "Next =>"
  197.       Height          =   255
  198.       Left            =   2520
  199.       TabIndex        =   12
  200.       TabStop         =   0   'False
  201.       Top             =   3840
  202.       Width           =   1215
  203.    End
  204.    Begin VB.CommandButton cmdPrevious 
  205.       Caption         =   "<= Previous"
  206.       Height          =   255
  207.       Left            =   1080
  208.       TabIndex        =   11
  209.       TabStop         =   0   'False
  210.       Top             =   3840
  211.       Width           =   1215
  212.    End
  213.    Begin VB.TextBox txtInput 
  214.       DataField       =   "PubID"
  215.       DataMember      =   "comPublishers"
  216.       DataSource      =   "denBooks"
  217.       Height          =   285
  218.       Index           =   0
  219.       Left            =   1320
  220.       Locked          =   -1  'True
  221.       TabIndex        =   10
  222.       TabStop         =   0   'False
  223.       Text            =   "Text1"
  224.       Top             =   120
  225.       Width           =   1215
  226.    End
  227.    Begin VB.Label Label1 
  228.       Caption         =   "Comments"
  229.       Height          =   255
  230.       Index           =   9
  231.       Left            =   120
  232.       TabIndex        =   28
  233.       Top             =   3360
  234.       Width           =   1215
  235.    End
  236.    Begin VB.Label Label1 
  237.       Caption         =   "FAX"
  238.       Height          =   255
  239.       Index           =   8
  240.       Left            =   120
  241.       TabIndex        =   27
  242.       Top             =   3000
  243.       Width           =   1215
  244.    End
  245.    Begin VB.Label Label1 
  246.       Caption         =   "Telephone"
  247.       Height          =   255
  248.       Index           =   7
  249.       Left            =   120
  250.       TabIndex        =   26
  251.       Top             =   2640
  252.       Width           =   1215
  253.    End
  254.    Begin VB.Label Label1 
  255.       Caption         =   "Zip"
  256.       Height          =   255
  257.       Index           =   6
  258.       Left            =   120
  259.       TabIndex        =   25
  260.       Top             =   2280
  261.       Width           =   1215
  262.    End
  263.    Begin VB.Label Label1 
  264.       Caption         =   "State"
  265.       Height          =   255
  266.       Index           =   5
  267.       Left            =   120
  268.       TabIndex        =   24
  269.       Top             =   1920
  270.       Width           =   1215
  271.    End
  272.    Begin VB.Label Label1 
  273.       Caption         =   "City"
  274.       Height          =   255
  275.       Index           =   4
  276.       Left            =   120
  277.       TabIndex        =   23
  278.       Top             =   1560
  279.       Width           =   1215
  280.    End
  281.    Begin VB.Label Label1 
  282.       Caption         =   "Address"
  283.       Height          =   255
  284.       Index           =   3
  285.       Left            =   120
  286.       TabIndex        =   22
  287.       Top             =   1200
  288.       Width           =   1215
  289.    End
  290.    Begin VB.Label Label1 
  291.       Caption         =   "Company Name"
  292.       Height          =   255
  293.       Index           =   2
  294.       Left            =   120
  295.       TabIndex        =   21
  296.       Top             =   840
  297.       Width           =   1215
  298.    End
  299.    Begin VB.Label Label1 
  300.       Caption         =   "Name"
  301.       Height          =   255
  302.       Index           =   1
  303.       Left            =   120
  304.       TabIndex        =   20
  305.       Top             =   480
  306.       Width           =   1215
  307.    End
  308.    Begin VB.Label Label1 
  309.       Caption         =   "Publisher ID"
  310.       Height          =   255
  311.       Index           =   0
  312.       Left            =   120
  313.       TabIndex        =   0
  314.       Top             =   120
  315.       Width           =   1215
  316.    End
  317. Attribute VB_Name = "frmPublishers"
  318. Attribute VB_GlobalNameSpace = False
  319. Attribute VB_Creatable = False
  320. Attribute VB_PredeclaredId = True
  321. Attribute VB_Exposed = False
  322. Option Explicit
  323. Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  324. Private Const HELP_FINDER = &HB&
  325. Private Sub ValidateData(AllOK As Boolean)
  326. Dim Message As String
  327. AllOK = True
  328. 'Check for name
  329. If Len(txtInput(1).Text) = 0 Then
  330.   Message = "You must enter a Publisher Name." & vbCrLf & Message
  331.   txtInput(1).SetFocus
  332.   AllOK = False
  333. End If
  334. If Not (AllOK) Then
  335.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  336. End If
  337. End Sub
  338. Private Sub cmdAddNew_Click()
  339. On Error GoTo HandleErrors
  340. Call SetState("Add")
  341. Exit Sub
  342. HandleErrors:
  343. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  344. Case vbAbort
  345.   Exit Sub
  346. Case vbRetry
  347.   Resume
  348. Case vbIgnore
  349.   Resume Next
  350. End Select
  351. End Sub
  352. Private Sub cmdCancel_Click()
  353. Call SetState("View")
  354. End Sub
  355. Private Sub cmdDelete_Click()
  356. Dim Response As Integer
  357. On Error GoTo HandleErrors
  358. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  359. If Response = vbNo Then
  360.   Exit Sub
  361. End If
  362. Exit Sub
  363. HandleErrors:
  364. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  365. Case vbAbort
  366.   Exit Sub
  367. Case vbRetry
  368.   Resume
  369. Case vbIgnore
  370.   Resume Next
  371. End Select
  372. End Sub
  373. Private Sub cmdEdit_Click()
  374. Call SetState("Edit")
  375. End Sub
  376. Private Sub cmdHelp_Click()
  377. Dim Rtn As Long
  378. Rtn = WinHelp(frmPublishers.hwnd, App.HelpFile, HELP_FINDER, CLng(0))
  379. End Sub
  380. Private Sub cmdNext_Click()
  381. denBooks.rscomPublishers.MoveNext
  382. If denBooks.rscomPublishers.EOF Then
  383.   Beep
  384.   denBooks.rscomPublishers.MoveLast
  385. End If
  386. End Sub
  387. Private Sub cmdPrevious_Click()
  388. denBooks.rscomPublishers.MovePrevious
  389. If denBooks.rscomPublishers.BOF Then
  390.   Beep
  391.   denBooks.rscomPublishers.MoveFirst
  392. End If
  393. End Sub
  394. Private Sub cmdSave_Click()
  395. Dim Valid As Boolean
  396. Call ValidateData(Valid)
  397. If Not (Valid) Then Exit Sub
  398. On Error GoTo HandleErrors
  399. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  400. Call SetState("View")
  401. Exit Sub
  402. HandleErrors:
  403. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  404. Case vbAbort
  405.   Exit Sub
  406. Case vbRetry
  407.   Resume
  408. Case vbIgnore
  409.   Resume Next
  410. End Select
  411. End Sub
  412. Private Sub SetState(AppState As String)
  413. Dim I As Integer
  414. Select Case AppState
  415. Case "View"
  416.   txtInput(0).BackColor = vbWhite
  417.   For I = 1 To 9
  418.     txtInput(I).Locked = True
  419.   Next I
  420.   cmdPrevious.Enabled = True
  421.   cmdNext.Enabled = True
  422.   cmdAddNew.Enabled = True
  423.   cmdSave.Enabled = False
  424.   cmdCancel.Enabled = False
  425.   cmdEdit.Enabled = True
  426.   cmdDelete.Enabled = True
  427.   cmdDone.Enabled = True
  428.   txtInput(1).SetFocus
  429. Case "Add", "Edit"
  430.   txtInput(0).BackColor = vbRed
  431.   For I = 1 To 9
  432.     txtInput(I).Locked = False
  433.   Next I
  434.   cmdPrevious.Enabled = False
  435.   cmdNext.Enabled = False
  436.   cmdAddNew.Enabled = False
  437.   cmdSave.Enabled = True
  438.   cmdCancel.Enabled = True
  439.   cmdEdit.Enabled = False
  440.   cmdDelete.Enabled = False
  441.   cmdDone.Enabled = False
  442.   txtInput(1).SetFocus
  443. End Select
  444. End Sub
  445. Private Sub Form_Activate()
  446. Call SetState("View")
  447. End Sub
  448. Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
  449. If KeyAscii = vbKeyReturn Then
  450.   If Index <> 9 Then
  451.     txtInput(Index + 1).SetFocus
  452.   Else
  453.     txtInput(1).SetFocus
  454.   End If
  455. End If
  456. End Sub
  457.